package com.hmkj.core.mapper.amount;

import com.hmkj.common.baseMapper.GenericMapper;
import com.hmkj.core.model.amount.PointLogModel;
import com.hmkj.core.po.user.PointLog;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 用户积分奖励记录表相关Dao接口<br>
 *
 * @author eproo
 * @date   2017-11-24 03:05:38
 */
public interface PointLogMapper extends GenericMapper< PointLog,Integer> {

    @Override
    @Select("SELECT count(1) FROM biz_point_log t LEFT JOIN biz_user u ON t.user_id = u.id  WHERE 1=1 ${whereSql} ${sortSql} ")
    long countBySqlJoin(Map<String, Object> params);

    @Override
    @Select("SELECT t.*, u.user_name AS 'u.userName',u.mobile AS 'u.mobile' FROM biz_point_log t LEFT JOIN biz_user u ON t.user_id = u.id WHERE 1=1 ${whereSql} ${sortSql} limit ${nowPage}, ${pageSize} ")
    List<PointLogModel> findListBySqlJoin(Map<String, Object> params);

    /**
     * 前台积分明细查询
     * @param param
     * @return
     */
    @Select("<script> SELECT count(*) FROM biz_point_log t WHERE t.user_id = #{userId}  AND t.del_flag = 1 </script>")
    Integer findCountForPointLogList(Map<String, Object> param);


    /**
     * 前台积分明细查询
     * @param param
     * @return
     */
    @Select("<script> SELECT t.* FROM biz_point_log t WHERE t.user_id = #{userId}  AND t.del_flag = 1 ORDER BY t.create_time DESC</script>")
    List<PointLog> findListForPointLoList(Map<String, Object> param);


    /**
     * 前台查询当日签到积分
     */
    @Select("SELECT t.* FROM biz_point_log t WHERE t.user_id = #{userId} AND t.nid = #{nid} AND t.create_time like CONCAT(date_format(#{createTime},'%Y-%m-%d'),'%') AND t.del_flag = 1")
    List<PointLog> findSignPointByTime(Map<String, Object> param);


}
